using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Web.UI;

namespace CSSStyleBuilder
{
	public partial class CSSStyleBuilderForm : Form
	{
		private StringBuilder m_css;
		private CSSStyleOptions m_Options;

		public CSSStyleOptions Options
		{
			get { return m_Options; }
			set { m_Options = value; }
		}

		public string Css
		{
			get { return m_css.ToString(); }
			set { m_css = new StringBuilder(value); }
		}

		public CSSStyleBuilderForm()
		{
			InitializeComponent();
			m_css = new StringBuilder();
			m_Options = new CSSStyleOptions();
		}

		private void CSSStyleBuilder_Load(object sender, EventArgs e)
		{
			
			#region Font related control initialization
			cmbFontFamily.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.FontFamily>();
			cmbFontSize.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.FontSize>();
			cmbFontStyle.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.FontStyle>();
			cmbFontVariant.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.FontVariant>();
			cmbFontWeight.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.FontWeight>();
			cmbLineHeightUnit.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			#endregion

			#region Border related control initialization
			cmbSingleBorderWidthUnit.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbSeparateBorderBottomWidthUnit.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbSeparateBorderLeftWidthUnit.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbSeparateBorderRightWidthUnit.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbSeparateBorderTopWidthUnit.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();

			cmbSingleBorderStyle.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.BorderStyle>();
			cmbSeparateBorderBottomStyle.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.BorderStyle>();
			cmbSeparateBorderLeftStyle.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.BorderStyle>();
			cmbSeparateBorderRightStyle.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.BorderStyle>();
			cmbSeparateBorderTopStyle.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.BorderStyle>();
			#endregion

			#region Padding and Margin related control Initialization
			cmbSinglePaddingUnits.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbSingleMarginUnits.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();

			cmbSeparatePaddingTopUnits.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbSeparatePaddingRightUnits.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbSeparatePaddingBottomUnits.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbSeparatePaddingLeftUnits.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();


			cmbSeparateMarginTopUnits.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbSeparateMarginRightUnits.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbSeparateMarginBottomUnits.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbSeparateMarginLeftUnits.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			#endregion

			#region Text related control initialization

			cmbWidthUnit.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbHeightUnit.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbOverflow.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Overflow>();
			cmbClear.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Clear>();
			cmbFloat.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Float>();
			cmbTextAlign.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.TextAlign>();
			cmbTextDecoration.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.TextDecoration>();
			cmbTextIndentUnit.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbLetterSpacingUnit.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbWordSpacingUnit.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbTextTransform.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.TextTransform>();
			cmbVerticalAlign.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.VerticalAlign>();
			cmbDisplay.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Display>();
			cmbVisibility.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Visibility>();
			cmbPosition.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Position>();
			cmbTopUnit.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbLeftUnit.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbRightUnit.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbBottomUnit.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
			cmbCursor.DataSource = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Cursor>();

			#endregion

			#region load options list if a css is supplied

			if (!string.IsNullOrEmpty(Css))
			{
				string[] arrayOfStyles = Css.Split(new char[] { ';' });

				foreach (string s in arrayOfStyles)
				{
					if (s.Length > 0)
					{
						string key = s.Split(new char[] { ':' })[0];
						string value1 = s.Split(new char[] { ':' })[1];
						string value = value1.Trim();
						try
						{
							HtmlTextWriterStyle htws = (HtmlTextWriterStyle)Enum.Parse(typeof(HtmlTextWriterStyle), key.Replace("-", ""), true);
							Options.StyleCollection.Add(htws, value);
						}
						catch (System.ArgumentException)
						{
							Options.StyleCollection.Add(key, value);
						}
					}
				}
			}
			#region Reading Font Options
			if (!string.IsNullOrEmpty(Options.Color))
			{
				txtColorCode.Text = Options.Color;
				lblColor.BackColor = Color.FromArgb(
					int.Parse(txtColorCode.Text.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier),
					int.Parse(txtColorCode.Text.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier),
					int.Parse(txtColorCode.Text.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
			}
			if (!string.IsNullOrEmpty(Options.BackgroundColor))
			{
				txtBackgroundColorCode.Text = Options.BackgroundColor;
				lblbachgroundColor.BackColor = Color.FromArgb(
					int.Parse(txtBackgroundColorCode.Text.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier),
					int.Parse(txtBackgroundColorCode.Text.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier),
					int.Parse(txtBackgroundColorCode.Text.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
			}
			if (!string.IsNullOrEmpty(Options.StyleCollection[HtmlTextWriterStyle.FontFamily]))
				cmbFontFamily.SelectedIndex = cmbFontFamily.Items.IndexOf(Options.StyleCollection[HtmlTextWriterStyle.FontFamily]);
			else
				cmbFontFamily.SelectedIndex = -1;
			if (!string.IsNullOrEmpty(Options.StyleCollection[HtmlTextWriterStyle.FontStyle]))
				cmbFontStyle.SelectedIndex = cmbFontStyle.Items.IndexOf(Options.StyleCollection[HtmlTextWriterStyle.FontStyle]);
			else
				cmbFontStyle.SelectedIndex = -1;
			if (!string.IsNullOrEmpty(Options.StyleCollection[HtmlTextWriterStyle.FontSize]))
				cmbFontSize.SelectedIndex = cmbFontSize.Items.IndexOf(Options.StyleCollection[HtmlTextWriterStyle.FontSize]);
			else
				cmbFontSize.SelectedIndex = -1;
			if (!string.IsNullOrEmpty(Options.StyleCollection[HtmlTextWriterStyle.FontVariant]))
				cmbFontVariant.SelectedIndex = cmbFontVariant.Items.IndexOf(Options.StyleCollection[HtmlTextWriterStyle.FontVariant]);
			else
				cmbFontVariant.SelectedIndex = -1;
			if (!string.IsNullOrEmpty(Options.StyleCollection[HtmlTextWriterStyle.FontWeight]))
				cmbFontWeight.SelectedIndex = cmbFontWeight.Items.IndexOf(Options.StyleCollection[HtmlTextWriterStyle.FontWeight]);
			else
				cmbFontWeight.SelectedIndex = -1;
			if (!string.IsNullOrEmpty(Options.LineHeight))
				txtLineHeight.Text = ExtractValue(Options.LineHeight);
			if (!string.IsNullOrEmpty(Options.LineHeight))
				cmbLineHeightUnit.SelectedIndex = ExtractUnit(Options.LineHeight);
			#endregion

			#region Reading Border Options

			#region Border Width Options
			if (!string.IsNullOrEmpty(Options.BorderWidth))
			{
				txtSingleBorderWidth.Text = ExtractValue(Options.BorderWidth);
				cmbSingleBorderWidthUnit.SelectedIndex = ExtractUnit(Options.BorderWidth);
				rbtnSingleBorderWidth.Checked = true;
				grpSeparateBorderWidth.Enabled = false;
			}
			else
			{
				bool foundAtLeastOneSeparateBorderWidthStyle = false;

				if (!string.IsNullOrEmpty(Options.BorderTopWidth))
				{
					txtSeparateBorderWidthTop.Text = ExtractValue(Options.BorderTopWidth);
					cmbSeparateBorderTopWidthUnit.SelectedIndex = ExtractUnit(Options.BorderTopWidth);
					foundAtLeastOneSeparateBorderWidthStyle = true;
				}

				if (!string.IsNullOrEmpty(Options.BorderRightWidth))
				{
					txtSeparateBorderWidthRight.Text = ExtractValue(Options.BorderRightWidth);
					cmbSeparateBorderRightWidthUnit.SelectedIndex = ExtractUnit(Options.BorderRightWidth);
					foundAtLeastOneSeparateBorderWidthStyle = true;
				}

				if (!string.IsNullOrEmpty(Options.BorderBottomWidth))
				{
					txtSeparateBorderWidthBottom.Text = ExtractValue(Options.BorderBottomWidth);
					cmbSeparateBorderBottomWidthUnit.SelectedIndex = ExtractUnit(Options.BorderBottomWidth);
					foundAtLeastOneSeparateBorderWidthStyle = true;
				}

				if (!string.IsNullOrEmpty(Options.BorderLeftWidth))
				{
					txtSeparateBorderWidthLeft.Text = ExtractValue(Options.BorderLeftWidth);
					cmbSeparateBorderLeftWidthUnit.SelectedIndex = ExtractUnit(Options.BorderLeftWidth);
					foundAtLeastOneSeparateBorderWidthStyle = true;
				}

				if (foundAtLeastOneSeparateBorderWidthStyle)
				{
					rbtnSeparateBorderWidth.Checked = true;
					txtSingleBorderWidth.Enabled = false;
					cmbSingleBorderWidthUnit.Enabled = false;
				}
			}
			#endregion

			#region Border Color Options

			if (!string.IsNullOrEmpty(Options.BorderColor))
			{
				txtSingleBorderColor.Text = Options.BorderColor;
				lblSingleBorderColor.BackColor = Color.FromArgb(
					int.Parse(txtSingleBorderColor.Text.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier),
					int.Parse(txtSingleBorderColor.Text.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier),
					int.Parse(txtSingleBorderColor.Text.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
				rbtnSingleBorderColor.Checked = true;
				rbtnSeparateBorderColors.Checked = false;
				grpSeparateBorderColor.Enabled = false;
			}
			else
			{
				bool foundAtLeastOneSeparateBorderColorStyle = false;

				if (!string.IsNullOrEmpty(Options.BorderTopColor))
				{
					txtSeparateBorderColorTop.Text = Options.BorderTopColor;
					lblSeparateBorderTopColor.BackColor = Color.FromArgb(
					int.Parse(txtSeparateBorderColorTop.Text.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier),
					int.Parse(txtSeparateBorderColorTop.Text.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier),
					int.Parse(txtSeparateBorderColorTop.Text.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
					foundAtLeastOneSeparateBorderColorStyle = true;
				}

				if (!string.IsNullOrEmpty(Options.BorderRightColor))
				{
					txtSeparateBorderColorRight.Text = Options.BorderRightColor;
					lblSeparateBorderRightColor.BackColor = Color.FromArgb(
					int.Parse(txtSeparateBorderColorRight.Text.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier),
					int.Parse(txtSeparateBorderColorRight.Text.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier),
					int.Parse(txtSeparateBorderColorRight.Text.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
					foundAtLeastOneSeparateBorderColorStyle = true;
				}

				if (!string.IsNullOrEmpty(Options.BorderBottomColor))
				{
					txtSeparateBorderColorBottom.Text = Options.BorderBottomColor;
					lblSeparateBorderBottomColor.BackColor = Color.FromArgb(
					int.Parse(txtSeparateBorderColorBottom.Text.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier),
					int.Parse(txtSeparateBorderColorBottom.Text.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier),
					int.Parse(txtSeparateBorderColorBottom.Text.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
					foundAtLeastOneSeparateBorderColorStyle = true;
				}

				if (!string.IsNullOrEmpty(Options.BorderLeftColor))
				{
					txtSeparateBorderColorLeft.Text = Options.BorderLeftColor;
					lblSeparateBorderLeftColor.BackColor = Color.FromArgb(
					int.Parse(txtSeparateBorderColorLeft.Text.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier),
					int.Parse(txtSeparateBorderColorLeft.Text.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier),
					int.Parse(txtSeparateBorderColorLeft.Text.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
					foundAtLeastOneSeparateBorderColorStyle = true;
				}

				if (foundAtLeastOneSeparateBorderColorStyle)
				{
					rbtnSeparateBorderColors.Checked = true;
					rbtnSingleBorderColor.Checked = false;
					txtSingleBorderColor.Enabled = false;
					lblSingleBorderColor.Enabled = false;
				}
			}
			#endregion

			#region Border Style Options

			if (!string.IsNullOrEmpty(Options.BorderStyle))
			{
				cmbSingleBorderStyle.SelectedIndex = cmbSingleBorderStyle.Items.IndexOf(Options.BorderStyle);

				rbtnSingleBorderStyle.Checked = true;
				rbtnSeparateBorderStyles.Checked = false;
				grpSeparateBorderStyle.Enabled = false;
			}
			else
			{
				bool foundAtLeastOneSeparateBorderStyleStyle = false;

				if (!string.IsNullOrEmpty(Options.BorderTopStyle))
				{
					cmbSeparateBorderTopStyle.SelectedIndex = cmbSeparateBorderTopStyle.Items.IndexOf(Options.BorderTopStyle);
					foundAtLeastOneSeparateBorderStyleStyle = true;
				}
				else
					cmbSeparateBorderTopStyle.SelectedIndex = -1;

				if (!string.IsNullOrEmpty(Options.BorderRightStyle))
				{
					cmbSeparateBorderRightStyle.SelectedIndex = cmbSeparateBorderRightStyle.Items.IndexOf(Options.BorderRightStyle);
					foundAtLeastOneSeparateBorderStyleStyle = true;
				}
				else
					cmbSeparateBorderRightStyle.SelectedIndex = -1;

				if (!string.IsNullOrEmpty(Options.BorderBottomStyle))
				{
					cmbSeparateBorderBottomStyle.SelectedIndex = cmbSeparateBorderBottomStyle.Items.IndexOf(Options.BorderBottomStyle);
					foundAtLeastOneSeparateBorderStyleStyle = true;
				}
				else
					cmbSeparateBorderBottomStyle.SelectedIndex = -1;

				if (!string.IsNullOrEmpty(Options.BorderLeftStyle))
				{
					cmbSeparateBorderLeftStyle.SelectedIndex = cmbSeparateBorderLeftStyle.Items.IndexOf(Options.BorderLeftStyle);
					foundAtLeastOneSeparateBorderStyleStyle = true;
				}
				else
					cmbSeparateBorderLeftStyle.SelectedIndex = -1;

				if (foundAtLeastOneSeparateBorderStyleStyle)
				{
					rbtnSeparateBorderStyles.Checked = true;
					rbtnSingleBorderStyle.Checked = false;
					cmbSingleBorderStyle.Enabled = false;
				}

				cmbSingleBorderStyle.SelectedIndex = -1;
			}

			#endregion

			#endregion

			#region Reading Padding and Margin Options

			#region Padding Options
			if (!string.IsNullOrEmpty(Options.Padding))
			{
				txtSinglePadding.Text = ExtractValue(Options.Padding);
				cmbSinglePaddingUnits.SelectedIndex = ExtractUnit(Options.Padding);
				rbtnSinglePadding.Checked = true;
				grpSeparatePaddings.Enabled = false;
			}
			else
			{
				bool foundAtLeastOneSeparatePadding = false;

				if (!string.IsNullOrEmpty(Options.PaddingTop))
				{
					txtSeparatePaddingTop.Text = ExtractValue(Options.PaddingTop);
					cmbSeparatePaddingTopUnits.SelectedIndex = ExtractUnit(Options.PaddingTop);
					foundAtLeastOneSeparatePadding = true;
				}

				if (!string.IsNullOrEmpty(Options.PaddingRight))
				{
					txtSeparatePaddingRight.Text = ExtractValue(Options.PaddingRight);
					cmbSeparatePaddingRightUnits.SelectedIndex = ExtractUnit(Options.PaddingRight);
					foundAtLeastOneSeparatePadding = true;
				}

				if (!string.IsNullOrEmpty(Options.PaddingBottom))
				{
					txtSeparatePaddingBottom.Text = ExtractValue(Options.PaddingBottom);
					cmbSeparatePaddingBottomUnits.SelectedIndex = ExtractUnit(Options.PaddingBottom);
					foundAtLeastOneSeparatePadding = true;
				}

				if (!string.IsNullOrEmpty(Options.PaddingLeft))
				{
					txtSeparatePaddingLeft.Text = ExtractValue(Options.PaddingLeft);
					cmbSeparatePaddingLeftUnits.SelectedIndex = ExtractUnit(Options.PaddingLeft);
					foundAtLeastOneSeparatePadding = true;
				}

				if (foundAtLeastOneSeparatePadding)
				{
					rbtnSeparatePadding.Checked = true;
					txtSinglePadding.Enabled = false;
					cmbSinglePaddingUnits.Enabled = false;
				}
			}
			#endregion

			#region Margin Options
			if (!string.IsNullOrEmpty(Options.Margin))
			{
				txtSingleMargin.Text = ExtractValue(Options.Margin);
				cmbSingleMarginUnits.SelectedIndex = ExtractUnit(Options.Margin);
				rbtnSingleMargin.Checked = true;
				grpSeparateMargins.Enabled = false;
			}
			else
			{
				bool foundAtLeastOneSeparateMargin = false;

				if (!string.IsNullOrEmpty(Options.MarginTop))
				{
					txtSeparateMarginsTop.Text = ExtractValue(Options.MarginTop);
					cmbSeparateMarginTopUnits.SelectedIndex = ExtractUnit(Options.MarginTop);
					foundAtLeastOneSeparateMargin = true;
				}

				if (!string.IsNullOrEmpty(Options.MarginRight))
				{
					txtSeparateMarginsRight.Text = ExtractValue(Options.MarginRight);
					cmbSeparateMarginRightUnits.SelectedIndex = ExtractUnit(Options.MarginRight);
					foundAtLeastOneSeparateMargin = true;
				}

				if (!string.IsNullOrEmpty(Options.MarginBottom))
				{
					txtSeparateMarginsBottom.Text = ExtractValue(Options.MarginBottom);
					cmbSeparateMarginBottomUnits.SelectedIndex = ExtractUnit(Options.MarginBottom);
					foundAtLeastOneSeparateMargin = true;
				}

				if (!string.IsNullOrEmpty(Options.MarginLeft))
				{
					txtSeparateMarginsLeft.Text = ExtractValue(Options.MarginLeft);
					cmbSeparateMarginLeftUnits.SelectedIndex = ExtractUnit(Options.MarginLeft);
					foundAtLeastOneSeparateMargin = true;
				}

				if (foundAtLeastOneSeparateMargin)
				{
					rbtnSeparateMargins.Checked = true;
					txtSingleMargin.Enabled = false;
					cmbSingleMarginUnits.Enabled = false;
				}
			}
			#endregion

			#endregion

			#region Reading Text Options

			if (!string.IsNullOrEmpty(Options.StyleCollection[HtmlTextWriterStyle.Width]))
			{
				txtWidth.Text = ExtractValue(Options.StyleCollection[HtmlTextWriterStyle.Width]);
				cmbWidthUnit.SelectedIndex = ExtractUnit(Options.StyleCollection[HtmlTextWriterStyle.Width]);
			}
			if (!string.IsNullOrEmpty(Options.StyleCollection[HtmlTextWriterStyle.Height]))
			{
				txtHeight.Text = ExtractValue(Options.StyleCollection[HtmlTextWriterStyle.Height]);
				cmbHeightUnit.SelectedIndex = ExtractUnit(Options.StyleCollection[HtmlTextWriterStyle.Height]);
			}
			if (!string.IsNullOrEmpty(Options.StyleCollection[HtmlTextWriterStyle.Overflow]))
				cmbOverflow.SelectedIndex = cmbOverflow.Items.IndexOf(Options.StyleCollection[HtmlTextWriterStyle.Overflow]);
			else
				cmbOverflow.SelectedIndex = -1;
			if (!string.IsNullOrEmpty(Options.Clear))
				cmbClear.SelectedIndex = cmbClear.Items.IndexOf(Options.Clear);
			else
				cmbClear.SelectedIndex = -1;
			if (!string.IsNullOrEmpty(Options.Float))
				cmbFloat.SelectedIndex = cmbFloat.Items.IndexOf(Options.Float);
			else
				cmbFloat.SelectedIndex = -1;
			if (!string.IsNullOrEmpty(Options.StyleCollection[HtmlTextWriterStyle.TextAlign]))
				cmbTextAlign.SelectedIndex = cmbTextAlign.Items.IndexOf(Options.StyleCollection[HtmlTextWriterStyle.TextAlign]);
			else
				cmbTextAlign.SelectedIndex = -1;
			if (!string.IsNullOrEmpty(Options.StyleCollection[HtmlTextWriterStyle.TextDecoration]))
				cmbTextDecoration.SelectedIndex = cmbTextDecoration.Items.IndexOf(Options.StyleCollection[HtmlTextWriterStyle.TextDecoration]);
			else
				cmbTextDecoration.SelectedIndex = -1;
			if (!string.IsNullOrEmpty(Options.TextIndent))
				txtTextIndent.Text = ExtractValue(Options.TextIndent);
			if (!string.IsNullOrEmpty(Options.TextIndent))
				cmbTextIndentUnit.SelectedIndex = ExtractUnit(Options.TextIndent);
			if (!string.IsNullOrEmpty(Options.LetterSpacing))
			{
				txtLetterSpacing.Text = ExtractValue(Options.LetterSpacing);
				cmbLetterSpacingUnit.SelectedIndex = ExtractUnit(Options.LetterSpacing);
			}
			if (!string.IsNullOrEmpty(Options.WordSpacing))
			{
				txtWordSpacing.Text = ExtractValue(Options.WordSpacing);
				cmbWordSpacingUnit.SelectedIndex = ExtractUnit(Options.WordSpacing);
			}
			if (!string.IsNullOrEmpty(Options.TextTransform))
				cmbTextTransform.SelectedIndex = cmbTextTransform.Items.IndexOf(Options.TextTransform);
			else
				cmbTextTransform.SelectedIndex = -1;
			if (!string.IsNullOrEmpty(Options.StyleCollection[HtmlTextWriterStyle.VerticalAlign]))
				cmbVerticalAlign.SelectedIndex = cmbVerticalAlign.Items.IndexOf(Options.StyleCollection[HtmlTextWriterStyle.VerticalAlign]);
			else
				cmbVerticalAlign.SelectedIndex = -1;
			if (!string.IsNullOrEmpty(Options.StyleCollection[HtmlTextWriterStyle.Display]))
				cmbDisplay.SelectedIndex = cmbDisplay.Items.IndexOf(Options.StyleCollection[HtmlTextWriterStyle.Display]);
			else
				cmbDisplay.SelectedIndex = -1;
			if (!string.IsNullOrEmpty(Options.StyleCollection[HtmlTextWriterStyle.Visibility]))
				cmbVisibility.SelectedIndex = cmbVisibility.Items.IndexOf(Options.StyleCollection[HtmlTextWriterStyle.Visibility]);
			else
				cmbVisibility.SelectedIndex = -1;
			if (!string.IsNullOrEmpty(Options.StyleCollection[HtmlTextWriterStyle.Position]))
				cmbPosition.SelectedIndex = cmbPosition.Items.IndexOf(Options.StyleCollection[HtmlTextWriterStyle.Position]);
			else
				cmbPosition.SelectedIndex = -1;
			if (!string.IsNullOrEmpty(Options.StyleCollection[HtmlTextWriterStyle.Top]))
			{
				txtTop.Text = ExtractValue(Options.StyleCollection[HtmlTextWriterStyle.Top]);
				cmbTopUnit.SelectedIndex = ExtractUnit(Options.StyleCollection[HtmlTextWriterStyle.Top]);
			}
			if (!string.IsNullOrEmpty(Options.StyleCollection[HtmlTextWriterStyle.Left]))
			{
				txtLeft.Text = ExtractValue(Options.StyleCollection[HtmlTextWriterStyle.Left]);
				cmbLeftUnit.SelectedIndex = ExtractUnit(Options.StyleCollection[HtmlTextWriterStyle.Left]);
			}
			if (!string.IsNullOrEmpty(Options.Right))
			{
				txtRight.Text = ExtractValue(Options.Right);
				cmbRightUnit.SelectedIndex = ExtractUnit(Options.Right);
			}
			if (!string.IsNullOrEmpty(Options.Bottom))
			{
				txtBottom.Text = ExtractValue(Options.Bottom);
				cmbBottomUnit.SelectedIndex = ExtractUnit(Options.Bottom);
			}
			if (!string.IsNullOrEmpty(Options.StyleCollection[HtmlTextWriterStyle.ZIndex]))
				txtZIndex.Text = Options.StyleCollection[HtmlTextWriterStyle.ZIndex];
			if (!string.IsNullOrEmpty(Options.StyleCollection[HtmlTextWriterStyle.Cursor]))
				cmbCursor.SelectedIndex = cmbCursor.Items.IndexOf(Options.StyleCollection[HtmlTextWriterStyle.Cursor]);
			else
				cmbCursor.SelectedIndex = -1;


			#endregion



			#endregion
		}

		private string ExtractValue(string p)
		{
			if (!string.IsNullOrEmpty(p))
			{
				List<string> listOfUnits = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
				foreach (string s in listOfUnits)
				{
					if (p.Contains(s))
					{
						return p.Substring(0, p.IndexOf(s));
					}
				}
			}
			return string.Empty;
		}

		private int ExtractUnit(string p)
		{
			if (!string.IsNullOrEmpty(p))
			{
				List<string> listOfUnits = CSSStyleOptions.GetEnumDescriptionList<CSSStyleBuilder.Units>();
				foreach (string s in listOfUnits)
				{
					if (p.Contains(s))
					{
						return listOfUnits.IndexOf(s);
					}
				}
			}
			return -1;
		}

		private void btnColor_Click(object sender, EventArgs e)
		{
			if (colorDialog1.ShowDialog() == DialogResult.OK)
			{
				string colorcode = "#" + ((colorDialog1.Color.R.ToString("X").Length == 1) ? "0" + colorDialog1.Color.R.ToString("X") : colorDialog1.Color.R.ToString("X")) + ((colorDialog1.Color.G.ToString("X").Length == 1) ? "0" + colorDialog1.Color.G.ToString("X") : colorDialog1.Color.G.ToString("X")) + ((colorDialog1.Color.B.ToString("X").Length == 1) ? "0" + colorDialog1.Color.B.ToString("X") : colorDialog1.Color.B.ToString("X"));
				txtColorCode.Text = colorcode;
				lblColor.BackColor = colorDialog1.Color;
				Options.Color = colorcode;
			}
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			#region Saving Font options
			if (txtColorCode.Text != string.Empty)
				Options.Color = txtColorCode.Text;
			if (txtBackgroundColorCode.Text != string.Empty)
				Options.BackgroundColor = txtBackgroundColorCode.Text;
			if (cmbFontFamily.Text != string.Empty)
				Options.StyleCollection.Add(HtmlTextWriterStyle.FontFamily, cmbFontFamily.Text);
			if (cmbFontStyle.Text != string.Empty)
				Options.StyleCollection.Add(HtmlTextWriterStyle.FontSize, cmbFontSize.Text);
			if (cmbFontStyle.Text != string.Empty)
				Options.StyleCollection.Add(HtmlTextWriterStyle.FontStyle, cmbFontStyle.Text);
			if (cmbFontVariant.Text != string.Empty)
				Options.StyleCollection.Add(HtmlTextWriterStyle.FontVariant, cmbFontVariant.Text);
			if (cmbFontWeight.Text != string.Empty)
				Options.StyleCollection.Add(HtmlTextWriterStyle.FontWeight, cmbFontWeight.Text);
			if (txtLineHeight.Text != string.Empty)
				Options.LineHeight = txtLineHeight.Text + cmbLineHeightUnit.Text;
			#endregion

			#region Saving Border options

			if (rbtnSingleBorderWidth.Checked)
			{
				if (txtSingleBorderWidth.Text != string.Empty)
					Options.BorderWidth = txtSingleBorderWidth.Text + cmbSingleBorderWidthUnit.Text;
			}
			else if (rbtnSeparateBorderWidth.Checked)
			{
				if (txtSeparateBorderWidthTop.Text != string.Empty)
					Options.BorderTopWidth = txtSeparateBorderWidthTop.Text + cmbSeparateBorderTopWidthUnit.Text;
				if (txtSeparateBorderWidthRight.Text != string.Empty)
					Options.BorderRightWidth = txtSeparateBorderWidthRight.Text + cmbSeparateBorderRightWidthUnit.Text;
				if (txtSeparateBorderWidthBottom.Text != string.Empty)
					Options.BorderBottomWidth = txtSeparateBorderWidthBottom.Text + cmbSeparateBorderBottomWidthUnit.Text;
				if (txtSeparateBorderWidthLeft.Text != string.Empty)
					Options.BorderLeftWidth = txtSeparateBorderWidthLeft.Text + cmbSeparateBorderLeftWidthUnit.Text;
			}

			if (rbtnSingleBorderColor.Checked)
			{
				if (txtSingleBorderColor.Text != string.Empty)
					Options.BorderColor = txtSingleBorderColor.Text;
			}
			else if (rbtnSeparateBorderColors.Checked)
			{
				if (txtSeparateBorderColorTop.Text != string.Empty)
					Options.BorderTopColor = txtSeparateBorderColorTop.Text;
				if (txtSeparateBorderColorRight.Text != string.Empty)
					Options.BorderRightColor = txtSeparateBorderColorRight.Text;
				if (txtSeparateBorderColorBottom.Text != string.Empty)
					Options.BorderBottomColor = txtSeparateBorderColorBottom.Text;
				if (txtSeparateBorderColorLeft.Text != string.Empty)
					Options.BorderLeftColor = txtSeparateBorderColorLeft.Text;
			}

			if (rbtnSingleBorderStyle.Checked)
			{
				if (cmbSingleBorderStyle.Text != string.Empty)
					Options.BorderStyle = cmbSingleBorderStyle.Text;
			}
			else if (rbtnSeparateBorderStyles.Checked)
			{
				if (cmbSeparateBorderTopStyle.Text != string.Empty)
					Options.BorderTopStyle = cmbSeparateBorderTopStyle.Text;
				if (cmbSeparateBorderRightStyle.Text != string.Empty)
					Options.BorderRightStyle = cmbSeparateBorderRightStyle.Text;
				if (cmbSeparateBorderBottomStyle.Text != string.Empty)
					Options.BorderBottomStyle = cmbSeparateBorderBottomStyle.Text;
				if (cmbSeparateBorderLeftStyle.Text != string.Empty)
					Options.BorderLeftStyle = cmbSeparateBorderLeftStyle.Text;
			}

			#endregion

			#region Saving Padding and Margin options

			if (rbtnSinglePadding.Checked)
			{
				if (txtSinglePadding.Text != string.Empty)
					Options.Padding = txtSinglePadding.Text + cmbSinglePaddingUnits.Text;
			}
			else if (rbtnSeparatePadding.Checked)
			{
				if (txtSeparatePaddingTop.Text != string.Empty)
					Options.PaddingTop = txtSeparatePaddingTop.Text + cmbSeparatePaddingTopUnits.Text;
				if (txtSeparatePaddingRight.Text != string.Empty)
					Options.PaddingRight = txtSeparatePaddingRight.Text + cmbSeparatePaddingRightUnits.Text;
				if (txtSeparatePaddingBottom.Text != string.Empty)
					Options.PaddingBottom = txtSeparatePaddingBottom.Text + cmbSeparatePaddingBottomUnits.Text;
				if (txtSeparatePaddingLeft.Text != string.Empty)
					Options.PaddingLeft = txtSeparatePaddingLeft.Text + cmbSeparatePaddingLeftUnits.Text;
			}

			if (rbtnSingleMargin.Checked)
			{
				if (txtSingleMargin.Text != string.Empty)
					Options.Margin = txtSingleMargin.Text + cmbSingleMarginUnits.Text;
			}
			else if (rbtnSeparateMargins.Checked)
			{
				if (txtSeparateMarginsTop.Text != string.Empty)
					Options.MarginTop = txtSeparateMarginsTop.Text + cmbSeparateMarginTopUnits.Text;
				if (txtSeparateMarginsRight.Text != string.Empty)
					Options.MarginRight = txtSeparateMarginsRight.Text + cmbSeparateMarginRightUnits.Text;
				if (txtSeparateMarginsBottom.Text != string.Empty)
					Options.MarginBottom = txtSeparateMarginsBottom.Text + cmbSeparateMarginBottomUnits.Text;
				if (txtSeparateMarginsLeft.Text != string.Empty)
					Options.MarginLeft = txtSeparateMarginsLeft.Text + cmbSeparateMarginLeftUnits.Text;
			}

			#endregion

			#region Saving Text options
			if (txtWidth.Text != string.Empty)
				Options.StyleCollection.Add(HtmlTextWriterStyle.Width, txtWidth.Text + cmbWidthUnit.Text);
			if (txtHeight.Text != string.Empty)
				Options.StyleCollection.Add(HtmlTextWriterStyle.Height, txtHeight.Text + cmbHeightUnit.Text);
			if (cmbOverflow.Text != string.Empty)
				Options.StyleCollection.Add(HtmlTextWriterStyle.Overflow, cmbOverflow.Text);
			if (cmbClear.Text != string.Empty)
				Options.Clear = cmbClear.Text;
			if (cmbFloat.Text != string.Empty)
				Options.Float = cmbFloat.Text;
			if (cmbTextAlign.Text != string.Empty)
				Options.StyleCollection.Add(HtmlTextWriterStyle.TextAlign, cmbTextAlign.Text);
			if (cmbTextDecoration.Text != string.Empty)
				Options.StyleCollection.Add(HtmlTextWriterStyle.TextDecoration, cmbTextDecoration.Text);
			if (txtTextIndent.Text != string.Empty)
				Options.TextIndent = txtTextIndent.Text + cmbTextIndentUnit.Text;
			if (txtLetterSpacing.Text != string.Empty)
				Options.LetterSpacing = txtLetterSpacing.Text + cmbLetterSpacingUnit.Text;
			if (txtWordSpacing.Text != string.Empty)
				Options.WordSpacing = txtWordSpacing.Text + cmbWordSpacingUnit.Text;
			if (cmbTextTransform.Text != string.Empty)
				Options.TextTransform = cmbTextTransform.Text;
			if (cmbVerticalAlign.Text != string.Empty)
				Options.StyleCollection.Add(HtmlTextWriterStyle.VerticalAlign, cmbVerticalAlign.Text);
			if (cmbDisplay.Text != string.Empty)
				Options.StyleCollection.Add(HtmlTextWriterStyle.Display, cmbDisplay.Text);
			if (cmbVisibility.Text != string.Empty)
				Options.StyleCollection.Add(HtmlTextWriterStyle.Visibility, cmbVisibility.Text);
			if (cmbPosition.Text != string.Empty)
				Options.StyleCollection.Add(HtmlTextWriterStyle.Position, cmbPosition.Text);
			if (txtTop.Text != string.Empty)
				Options.StyleCollection.Add(HtmlTextWriterStyle.Top, txtTop.Text + cmbTopUnit.Text);
			if (txtLeft.Text != string.Empty)
				Options.StyleCollection.Add(HtmlTextWriterStyle.Left, txtLeft.Text + cmbLeftUnit.Text);
			if (txtRight.Text != string.Empty)
				Options.Right = txtRight.Text + cmbRightUnit.Text;
			if (txtBottom.Text != string.Empty)
				Options.Bottom = txtBottom.Text + cmbBottomUnit.Text;
			if (txtZIndex.Text != string.Empty)
				Options.StyleCollection.Add(HtmlTextWriterStyle.ZIndex, txtZIndex.Text);
			if (cmbCursor.Text != string.Empty)
				Options.StyleCollection.Add(HtmlTextWriterStyle.Cursor, cmbCursor.Text);
			#endregion

			Css = Options.StyleCollection.Value;

			this.DialogResult = DialogResult.OK;
			this.Close();
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;
			this.Close();
		}

		private void btnBackgroundColor_Click(object sender, EventArgs e)
		{
			if (colorDialog1.ShowDialog() == DialogResult.OK)
			{
				string colorcode = "#" + ((colorDialog1.Color.R.ToString("X").Length == 1) ? "0" + colorDialog1.Color.R.ToString("X") : colorDialog1.Color.R.ToString("X")) + ((colorDialog1.Color.G.ToString("X").Length == 1) ? "0" + colorDialog1.Color.G.ToString("X") : colorDialog1.Color.G.ToString("X")) + ((colorDialog1.Color.B.ToString("X").Length == 1) ? "0" + colorDialog1.Color.B.ToString("X") : colorDialog1.Color.B.ToString("X"));
				txtBackgroundColorCode.Text = colorcode;
				lblbachgroundColor.BackColor = colorDialog1.Color;
			}
		}

		private void tableLayoutPanel3_Paint(object sender, PaintEventArgs e)
		{

		}

		private void rbtnSingleBorderWidth_CheckedChanged(object sender, EventArgs e)
		{
			grpSeparateBorderWidth.Enabled = false;
			txtSingleBorderWidth.Enabled = true;
			cmbSingleBorderWidthUnit.Enabled = true;
		}

		private void rbtnSeparateBorderWidth_CheckedChanged(object sender, EventArgs e)
		{
			grpSeparateBorderWidth.Enabled = true;
			txtSingleBorderWidth.Enabled = false;
			cmbSingleBorderWidthUnit.Enabled = false;
		}

		private void btnSingleBorderColor_Click(object sender, EventArgs e)
		{
			if (colorDialog1.ShowDialog() == DialogResult.OK)
			{
				string colorcode = "#" + ((colorDialog1.Color.R.ToString("X").Length == 1) ? "0" + colorDialog1.Color.R.ToString("X") : colorDialog1.Color.R.ToString("X")) + ((colorDialog1.Color.G.ToString("X").Length == 1) ? "0" + colorDialog1.Color.G.ToString("X") : colorDialog1.Color.G.ToString("X")) + ((colorDialog1.Color.B.ToString("X").Length == 1) ? "0" + colorDialog1.Color.B.ToString("X") : colorDialog1.Color.B.ToString("X"));
				txtSingleBorderColor.Text = colorcode;
				lblSingleBorderColor.BackColor = colorDialog1.Color;
			}
		}

		private void btnSeparateBorderTopColor_Click(object sender, EventArgs e)
		{
			if (colorDialog1.ShowDialog() == DialogResult.OK)
			{
				string colorcode = "#" + ((colorDialog1.Color.R.ToString("X").Length == 1) ? "0" + colorDialog1.Color.R.ToString("X") : colorDialog1.Color.R.ToString("X")) + ((colorDialog1.Color.G.ToString("X").Length == 1) ? "0" + colorDialog1.Color.G.ToString("X") : colorDialog1.Color.G.ToString("X")) + ((colorDialog1.Color.B.ToString("X").Length == 1) ? "0" + colorDialog1.Color.B.ToString("X") : colorDialog1.Color.B.ToString("X"));
				txtSeparateBorderColorTop.Text = colorcode;
				lblSeparateBorderTopColor.BackColor = colorDialog1.Color;
			}
		}

		private void btnSeparateBorderLeftColor_Click(object sender, EventArgs e)
		{
			if (colorDialog1.ShowDialog() == DialogResult.OK)
			{
				string colorcode = "#" + ((colorDialog1.Color.R.ToString("X").Length == 1) ? "0" + colorDialog1.Color.R.ToString("X") : colorDialog1.Color.R.ToString("X")) + ((colorDialog1.Color.G.ToString("X").Length == 1) ? "0" + colorDialog1.Color.G.ToString("X") : colorDialog1.Color.G.ToString("X")) + ((colorDialog1.Color.B.ToString("X").Length == 1) ? "0" + colorDialog1.Color.B.ToString("X") : colorDialog1.Color.B.ToString("X"));
				txtSeparateBorderColorLeft.Text = colorcode;
				lblSeparateBorderLeftColor.BackColor = colorDialog1.Color;
			}
		}

		private void btnSeparateBorderRightColor_Click(object sender, EventArgs e)
		{
			if (colorDialog1.ShowDialog() == DialogResult.OK)
			{
				string colorcode = "#" + ((colorDialog1.Color.R.ToString("X").Length == 1) ? "0" + colorDialog1.Color.R.ToString("X") : colorDialog1.Color.R.ToString("X")) + ((colorDialog1.Color.G.ToString("X").Length == 1) ? "0" + colorDialog1.Color.G.ToString("X") : colorDialog1.Color.G.ToString("X")) + ((colorDialog1.Color.B.ToString("X").Length == 1) ? "0" + colorDialog1.Color.B.ToString("X") : colorDialog1.Color.B.ToString("X"));
				txtSeparateBorderColorRight.Text = colorcode;
				lblSeparateBorderRightColor.BackColor = colorDialog1.Color;
			}
		}

		private void btnSeparateBorderBottomColor_Click(object sender, EventArgs e)
		{
			if (colorDialog1.ShowDialog() == DialogResult.OK)
			{
				string colorcode = "#" + ((colorDialog1.Color.R.ToString("X").Length == 1) ? "0" + colorDialog1.Color.R.ToString("X") : colorDialog1.Color.R.ToString("X")) + ((colorDialog1.Color.G.ToString("X").Length == 1) ? "0" + colorDialog1.Color.G.ToString("X") : colorDialog1.Color.G.ToString("X")) + ((colorDialog1.Color.B.ToString("X").Length == 1) ? "0" + colorDialog1.Color.B.ToString("X") : colorDialog1.Color.B.ToString("X"));
				txtSeparateBorderColorBottom.Text = colorcode;
				lblSeparateBorderBottomColor.BackColor = colorDialog1.Color;
			}
		}

		private void rbtnSingleBorderColor_CheckedChanged(object sender, EventArgs e)
		{
			grpSeparateBorderColor.Enabled = false;
			txtSingleBorderColor.Enabled = true;
			lblSingleBorderColor.Enabled = true;
			btnSingleBorderColor.Enabled = true;
		}

		private void rbtnSeparateBorderColors_CheckedChanged(object sender, EventArgs e)
		{
			grpSeparateBorderColor.Enabled = true;
			txtSingleBorderColor.Enabled = false;
			lblSingleBorderColor.Enabled = false;
			btnSingleBorderColor.Enabled = false;
		}

		private void rbtnSingleButtonStyle_CheckedChanged(object sender, EventArgs e)
		{
			grpSeparateBorderStyle.Enabled = false;
			cmbSingleBorderStyle.Enabled = true;
		}

		private void rbtnSeparateButtonStyle_CheckedChanged(object sender, EventArgs e)
		{
			grpSeparateBorderStyle.Enabled = true;
			cmbSingleBorderStyle.Enabled = false;
		}

		private void rbtnSinglePadding_CheckedChanged(object sender, EventArgs e)
		{
			grpSeparatePaddings.Enabled = false;
			txtSinglePadding.Enabled = true;
			cmbSinglePaddingUnits.Enabled = true;
		}

		private void rbtnSeparatePadding_CheckedChanged(object sender, EventArgs e)
		{
			grpSeparatePaddings.Enabled = true;
			txtSinglePadding.Enabled = false;
			cmbSinglePaddingUnits.Enabled = false;
		}

		private void rbtnSingleMargin_CheckedChanged(object sender, EventArgs e)
		{
			grpSeparateMargins.Enabled = false;
			txtSingleMargin.Enabled = true;
			cmbSingleMarginUnits.Enabled = true;
		}

		private void rbtnSeparateMargins_CheckedChanged(object sender, EventArgs e)
		{
			grpSeparateMargins.Enabled = true;
			txtSingleMargin.Enabled = false;
			cmbSingleMarginUnits.Enabled = false;
		}

	}
}